package com.ymatou.iapi.notify.testcase;

import com.ymatou.iapi.notify.parameter.GetNotifyCountBean;
import com.ymatou.iapi.notify.parameter.SendNotifyBean;
import com.ymatou.iapi.notify.service.GetNotifyCountCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.NotifyCallService;
import com.ymttest.database.sqlwapper.ImDefaultWapper;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
*获取通知未读计数
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetNotifyCount{
	private static GetNotifyCountBean getnotifycountBean;
	private static GetNotifyCountCall getnotifycountCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取通知未读计数");
	}

	@Before
	public void caseUp() {
		getnotifycountBean=new GetNotifyCountBean();
		getnotifycountCall=new GetNotifyCountCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getnotifycountCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetNotifyCount_01() {
		Logger.start(true,"获取通知未读计数,码头通知");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer userId = urrc.getUserid();
			SendNotifyBean sendNotifyBean = NotifyCallService.initSendNotify(30156393,userId);
			NotifyCallService.SendNotify(sendNotifyBean);
			Thread.sleep(2000);
			List<Integer> list = new ArrayList<>();
			list.add(sendNotifyBean.getNotifySenderUserId());
			getnotifycountBean.setSenderIdList(list);
			getnotifycountBean.setUserId(userId);
			getnotifycountCall.setData(getnotifycountBean);
			getnotifycountCall.callService();			
			Logger.verifyEquals("Success",getnotifycountCall.getString("Status"),"验证Status");
			List<Map> arr = new ImDefaultWapper().selectImNotifyByToUserId(userId);
			Integer count = 0;
			for (Map map:arr
				 ) {
				if(Integer.parseInt(map.get("IsRead").toString()) == 0){
					count++;
				}
			}
			String[] arr1 = getnotifycountCall.getString("Result").split(":");
			String[] arr2 = arr1[1].split("}");
			Logger.debug(arr2[0]);
			Logger.verifyEquals(arr2[0],count.toString(),"验证未读数");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetNotifyCount_02() {
		Logger.start(true,"获取通知未读计数,促销新品");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer userId = urrc.getUserid();
			SendNotifyBean sendNotifyBean = NotifyCallService.initSendNotify(3791822,userId);
			NotifyCallService.SendNotify(sendNotifyBean);
			Thread.sleep(2000);
			List<Integer> list = new ArrayList<>();
			list.add(sendNotifyBean.getNotifySenderUserId());
			getnotifycountBean.setSenderIdList(list);
			getnotifycountBean.setUserId(userId);
			getnotifycountCall.setData(getnotifycountBean);
			getnotifycountCall.callService();
			Logger.verifyEquals("Success",getnotifycountCall.getString("Status"),"验证Status");
			List<Map> arr = new ImDefaultWapper().selectImNotifyByToUserId(userId);
			Integer count = 0;
			for (Map map:arr
			) {
				if(Integer.parseInt(map.get("IsRead").toString()) == 0){
					count++;
				}
			}
			String[] arr1 = getnotifycountCall.getString("Result").split(":");
			String[] arr2 = arr1[1].split("}");
			Logger.debug(arr2[0]);
			Logger.verifyEquals(arr2[0],count.toString(),"验证未读数");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetNotifyCount_03() {
		Logger.start(true,"获取通知未读计数,互动");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer userId = urrc.getUserid();
			SendNotifyBean sendNotifyBean = NotifyCallService.initSendNotify(30156418,userId);
			NotifyCallService.SendNotify(sendNotifyBean);
			Thread.sleep(2000);
			List<Integer> list = new ArrayList<>();
			list.add(sendNotifyBean.getNotifySenderUserId());
			getnotifycountBean.setSenderIdList(list);
			getnotifycountBean.setUserId(userId);
			getnotifycountCall.setData(getnotifycountBean);
			getnotifycountCall.callService();
			Logger.verifyEquals("Success",getnotifycountCall.getString("Status"),"验证Status");
			List<Map> arr = new ImDefaultWapper().selectImNotifyByToUserId(userId);
			Integer count = 0;
			for (Map map:arr
			) {
				if(Integer.parseInt(map.get("IsRead").toString()) == 0){
					count++;
				}
			}
			String[] arr1 = getnotifycountCall.getString("Result").split(":");
			String[] arr2 = arr1[1].split("}");
			Logger.debug(arr2[0]);
			Logger.verifyEquals(arr2[0],count.toString(),"验证未读数");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetNotifyCount_04() {
		Logger.start(true,"获取通知未读计数,订单助手");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer userId = urrc.getUserid();
			SendNotifyBean sendNotifyBean = NotifyCallService.initSendNotify(3791813,userId);
			NotifyCallService.SendNotify(sendNotifyBean);
			Thread.sleep(2000);
			List<Integer> list = new ArrayList<>();
			list.add(sendNotifyBean.getNotifySenderUserId());
			getnotifycountBean.setSenderIdList(list);
			getnotifycountBean.setUserId(userId);
			getnotifycountCall.setData(getnotifycountBean);
			getnotifycountCall.callService();
			Logger.verifyEquals("Success",getnotifycountCall.getString("Status"),"验证Status");
			List<Map> arr = new ImDefaultWapper().selectImNotifyByToUserId(userId);
			Integer count = 0;
			for (Map map:arr
			) {
				if(Integer.parseInt(map.get("IsRead").toString()) == 0){
					count++;
				}
			}
			String[] arr1 = getnotifycountCall.getString("Result").split(":");
			String[] arr2 = arr1[1].split("}");
			Logger.debug(arr2[0]);
			Logger.verifyEquals(arr2[0],count.toString(),"验证未读数");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}


}